package com.xinqi.modules.sys.stats.controller.admin;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.stats.dto.req.ClassTeachingDayStCreateDTO;
import com.xinqi.modules.sys.stats.dto.req.ClassTeachingDayStQueryDTO;
import com.xinqi.modules.sys.stats.dto.req.ClassTeachingDayStUpdateDTO;
import com.xinqi.modules.sys.stats.dto.req.ClassTeachingOverviewQueryDTO;
import com.xinqi.modules.sys.stats.dto.rsp.ClassOverviewResultDTO;
import com.xinqi.modules.sys.stats.dto.rsp.ClassTeachingDayStResultDTO;
import com.xinqi.modules.sys.stats.service.ClassTeachingDayStService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 班级教学数据统计WEB控制层
 *
 * @author: wenjie
 * @date: 2023/08/24
 */

@Slf4j
@Tag(name = "class-teaching-day-st-Admin", description = "班级教学数据统计Admin接口")
@RestController
@RequestMapping("/admin/class-teaching-day-st")
@RequiredArgsConstructor
public class ClassTeachingDayStAdminController {
    private final ClassTeachingDayStService classTeachingDayStService;

    /**
     * 班级教学数据统计-分页
     */
    @Operation(summary = "班级教学数据统计-分页")
    @GetMapping("/page")
    public R<PageInfo<ClassTeachingDayStResultDTO>> page(@ParameterObject ClassTeachingDayStQueryDTO dto) {
        PageInfo<ClassTeachingDayStResultDTO> page = classTeachingDayStService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 班级教学数据统计-详情
     */
    @Operation(summary = "班级教学数据统计-详情")
    @GetMapping("/{id}")
    public R<ClassTeachingDayStResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        ClassTeachingDayStResultDTO dto = classTeachingDayStService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增班级教学数据统计
     */
    @Operation(summary = "新增班级教学数据统计")
    @PostMapping
    public R<Long> insert(@RequestBody ClassTeachingDayStCreateDTO dto) {
        return R.data(classTeachingDayStService.insert(dto));
    }

    /**
     * 修改班级教学数据统计
     */
    @Operation(summary = "修改班级教学数据统计")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id, @RequestBody ClassTeachingDayStUpdateDTO dto) {
        dto.setId(id);
        return R.data(classTeachingDayStService.updateById(dto));
    }

    /**
     * 删除班级教学数据统计
     */
    @Operation(summary = "删除班级教学数据统计")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(classTeachingDayStService.deleteById(id));
    }

    /**
     * 班级教学数据统计-概览
     */
    @Operation(summary = "班级教学数据统计-概览")
    @GetMapping("/overview")
    public R<ClassOverviewResultDTO> overview(ClassTeachingOverviewQueryDTO query) {
        ClassOverviewResultDTO dto = classTeachingDayStService.overview(query);
        return R.data(dto);
    }

    /**
     * 班级教学数据统计-更新
     */
    @Operation(summary = "班级教学数据统计-更新")
    @PostMapping("/update-today")
    public R<Boolean> updateToday() {
        log.info("classTeachingDayUpdate...start...");
        classTeachingDayStService.updateToday();
        log.info("classTeachingDayUpdate...end...");
        return R.data(true);
    }

}
